package com.ews.onlineexchange.model;

import java.util.Date;

import javax.persistence.Entity;
import javax.persistence.ManyToOne;
import javax.persistence.Transient;
import javax.validation.constraints.NotNull;

@Entity
public class ContractRecord extends DataEntity {

	/**
	 * 合同归档 采购方提交 管理员查询
	 */
	private static final long	serialVersionUID	= 1L;

	private Bulletin			bulletin;
	private String				projectName;
	private String				buyerName;
	private String				supplierName;
	private String				limitOfTime;
	private String				amountOfInvestment;
	private String				projectOverview;

	@ManyToOne
	@NotNull
	public Bulletin getBulletin() {
		return bulletin;
	}

	public void setBulletin(Bulletin bulletin) {
		this.bulletin = bulletin;
	}

	@NotNull
	public String getProjectName() {
		return projectName;
	}

	public void setProjectName(String projectName) {
		this.projectName = projectName;
	}

	@NotNull
	public String getBuyerName() {
		return buyerName;
	}

	public void setBuyerName(String buyerName) {
		this.buyerName = buyerName;
	}

	@NotNull
	public String getSupplierName() {
		return supplierName;
	}

	public void setSupplierName(String supplierName) {
		this.supplierName = supplierName;
	}

	@NotNull
	public String getLimitOfTime() {
		return limitOfTime;
	}

	public void setLimitOfTime(String limitOfTime) {
		this.limitOfTime = limitOfTime;
	}

	@NotNull
	public String getAmountOfInvestment() {
		return amountOfInvestment;
	}

	public void setAmountOfInvestment(String amountOfInvestment) {
		this.amountOfInvestment = amountOfInvestment;
	}

	@NotNull
	public String getProjectOverview() {
		return projectOverview;
	}

	public void setProjectOverview(String projectOverview) {
		this.projectOverview = projectOverview;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = super.hashCode();
		result = prime * result + ((amountOfInvestment == null) ? 0 : amountOfInvestment.hashCode());
		result = prime * result + ((bulletin == null) ? 0 : bulletin.hashCode());
		result = prime * result + ((buyerName == null) ? 0 : buyerName.hashCode());
		result = prime * result + ((limitOfTime == null) ? 0 : limitOfTime.hashCode());
		result = prime * result + ((projectName == null) ? 0 : projectName.hashCode());
		result = prime * result + ((projectOverview == null) ? 0 : projectOverview.hashCode());
		result = prime * result + ((supplierName == null) ? 0 : supplierName.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (!super.equals(obj))
			return false;
		if (getClass() != obj.getClass())
			return false;
		ContractRecord other = (ContractRecord) obj;
		if (amountOfInvestment == null) {
			if (other.amountOfInvestment != null)
				return false;
		} else if (!amountOfInvestment.equals(other.amountOfInvestment))
			return false;
		if (bulletin == null) {
			if (other.bulletin != null)
				return false;
		} else if (!bulletin.equals(other.bulletin))
			return false;
		if (buyerName == null) {
			if (other.buyerName != null)
				return false;
		} else if (!buyerName.equals(other.buyerName))
			return false;
		if (limitOfTime == null) {
			if (other.limitOfTime != null)
				return false;
		} else if (!limitOfTime.equals(other.limitOfTime))
			return false;
		if (projectName == null) {
			if (other.projectName != null)
				return false;
		} else if (!projectName.equals(other.projectName))
			return false;
		if (projectOverview == null) {
			if (other.projectOverview != null)
				return false;
		} else if (!projectOverview.equals(other.projectOverview))
			return false;
		if (supplierName == null) {
			if (other.supplierName != null)
				return false;
		} else if (!supplierName.equals(other.supplierName))
			return false;
		return true;
	}

	@Transient
	public boolean updateable () {
		Date updateableDate = getCreateDate();
		updateableDate.setHours(updateableDate.getHours()+3);
		if(updateableDate.before(new Date()))
			return false;
		return true;			
	}
}
